#!/usr/bin/perl -w -I/opt/Lin/McAfee
#exit;

use strict;
use FORK;

use LWP::UserAgent;
use LWP::ConnCache;

my $ru = LWP::UserAgent->new;
$ru->conn_cache(LWP::ConnCache->new());

chdir '/opt/McAfee/pool';
my $Base='http://mine/WU/Current/VSCANDAT1000/DAT/0000/';
my $need='need.log';
my $ini='delta.ini';
$ru->agent("Gimly McAfee Linux Updater/1.0");
$\="\n",$,="\t";

#   $ru->mirror('http://mine/cgi-bin/delta.cgi','sums.lst');
    $ru->mirror($Base.$ini,$ini);

`./parse.pl > $need`;
if(4<-s $need)
{
    my $pid=DoFork();

    open NEED,$need;
    chdir 'inc';
    while (<NEED>)
    {
	chomp;
	if (s/##.*$//s)
	{
    	    my $r=$ru->mirror($Base.$_, $_);
	    die("$_: ".$r->status_line) unless $r->is_success;
	} else {s/#.*$//s or chomp}
	print "Apply:",$_;
	print FORK::OUT;
    }
    chdir '..';
    close FORK::OUT;
    waitpid $pid,0 if $pid>0;
} else {
    open NEED,$need;$_=<NEED>;close NEED;
    print "Already",$_
}
